var SortTool = function () {

    this.sortData = null;

    this.sorttype = null;

    this.json = {};

};

SortTool.prototype = {

    setItem:function( json )
    {
        for( var i in json )
        {
            this.json[ i ] = json[ i ];
        }

        this.sortData = this.json["d"]["r"]["i"];
    },

    sortDescItem: function ( target )
    {
        this._bubbleSort( target ,"desc" );

        return this.json;
    },

    sortAscItem: function ( target )
    {
        this._bubbleSort( target ,"asc" );

        return this.json;
    },

    _bubbleSort: function( target , type ) {

        var i = 0,
            len = this.sortData.length,
            array = this.sortData,
            j,
            d;

        this.sorttype = type ;

        for (; i < len; i++ )
        {

            for ( j = 0; j < len; j++ )
            {

                if ( type=="asc" && array[ i ][ target ] < array[ j ][ target ] )
                {
                    d = array[ j ];

                    array[ j ] = array[ i ];

                    array[ i ] = d;
                }
                else if( type=="desc" && array[ i ][ target ] > array[ j ][ target ] )
                {
                    d = array[ j ];

                    array[ j ] = array[ i ];

                    array[ i ] = d;
                }
            }
        }
    }

};